$(function(){
    var counter = 0;
    // 每页展示4个
    var num = 4;
    var pageStart = 0,pageEnd = 0;

    // dropload
    $('.main').dropload({
        scrollArea : window,
        loadDownFn : function(me){
            $.ajax({
                type: 'GET',
                url: 'js/more.json',
                dataType: 'json',
                success: function(data){
                    var result = '';
                    counter++;
                    pageEnd = num * counter;
                    pageStart = pageEnd - num;
                    for(var i = pageStart; i < pageEnd; i++){
                        result +=   '<tr class="pd">\
										<td class="inner-pd"><div class="img-box"><img src="'+data.lists[i].pic+'" alt=""></div></td>\
										<td class="pr">\
											<table class="inner-tb">\
												<tbody>\
													<tr>\
														<td class="name">王小二</td>\
														<td>'+data.lists[i].date+'</td>\
														<td>17:45</td>\
													</tr>\
													<tr>\
														<td>已获积分：</td>\
														<td class="ntegral"> 28888</td>\
														<td class="number">好友人数：<span>10</span></td>\
													</tr>\
												</tbody>\
											</table>\
											<div class="second">TOP3</div>\
										</td>\
									</tr>';
                        if((i + 1) >= data.lists.length){
                            // 锁定
                            me.lock();
                            // 无数据
                            me.noData();
                            break;
                        }
                    }
                    // 为了测试，延迟1秒加载
                    setTimeout(function(){
                        $('.wraper-tb>tbody').append(result);
                        // 每次数据加载完，必须重置
                        me.resetload();
                    },1000);
                },
                error: function(xhr, type){
                    alert('Ajax error!');
                    // 即使加载出错，也得重置
                    me.resetload();
                }
            });
        }
    });
});